(function() {

    var objectToQueryString = function(obj) {
        return Object.keys(obj).map(function(key) {
            return encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]);
        }).join('&');
    }

    var WXTransporter = function(_request) {
        var _ajax_url = _request.url + "/" + _request.interfaceName + "." + _request.methodName + "?" + objectToQueryString(_request.parameters);

        wx.request({
            url : _ajax_url,
            data : _request.requestBody,
            header : _request.headers,
            method : "POST",
            success : function(_response) {
                _request.responseBody = _response.data;
                _request.responseHandler(_request)
            },
            fail : function(_response) {
                _request.error = new Error(_response);
                _request.responseHandler(_request)
            }
        });
    };

    // 挂载根对象
    var _root = wx;

    _root.WXTransporter = WXTransporter;
})();